package cn.wolfcode.rbac.util;


import cn.wolfcode.rbac.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.Set;

public class CurrentUtil {
    public static final String EMPLOYEE_SESSION = "EMPLOYEE_SESSION";
    public static final String EXPRESSION_SESSION = "EXPRESSION_SESSION";

    public static HttpSession getSession(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }

    public static void setCurrent(Employee employee){
        getSession().setAttribute(CurrentUtil.EMPLOYEE_SESSION,employee);
    }

    public static Employee getCurrent(){
        return (Employee) getSession().getAttribute(CurrentUtil.EMPLOYEE_SESSION);
    }


    public static void setExpression(Set<String> expressions){
        getSession().setAttribute(CurrentUtil.EXPRESSION_SESSION,expressions);
    }

    public static Set<String> getExpression(){
        return (Set<String>) getSession().getAttribute(CurrentUtil.EXPRESSION_SESSION);
    }
}
